package com.wang.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wang.appuser.api.model.UserRealName;
import com.wang.common.model.dto.PageResponseResult;
import com.wang.common.model.dto.ResponseResult;
import com.wang.user.mapper.AuditUserMapper;
import com.wang.user.service.AuditUserService;
import com.wang.appuser.api.model.AuthDto;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author WN
 * @date：2024/03/11 19:04
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class AuditUserServiceImpl implements AuditUserService {

    private final AuditUserMapper auditUserMapper;
    @Override
    public ResponseResult list(AuthDto authDto) {
        PageHelper.startPage(authDto.getPage(), authDto.getSize());
        LambdaQueryWrapper<UserRealName> wrapper = Wrappers.lambdaQuery();
        if (authDto.getStatus() != null){
            wrapper.eq(UserRealName::getStatus, authDto.getStatus());
        }
        List<UserRealName> list = auditUserMapper.selectList(wrapper);
        PageInfo<UserRealName> info = new PageInfo<>(list);
        PageResponseResult pageResult =
                new PageResponseResult(info.getPageNum(), info.getSize(), (int) info.getTotal());
        return pageResult.okResult(info.getList());
    }

    @Override
    public ResponseResult authPass(AuthDto dto) {
        UserRealName userRealName = new UserRealName();
        userRealName.setId(dto.getId());
        userRealName.setStatus((short) 9);
        return ResponseResult.okResult(auditUserMapper.updateById(userRealName));
    }

    @Override
    public ResponseResult authFail(AuthDto dto) {
        UserRealName userRealName = new UserRealName();
        userRealName.setId(dto.getId());
        userRealName.setStatus((short) 2);
        userRealName.setReason(dto.getMsg());
        return ResponseResult.okResult(auditUserMapper.updateById(userRealName));
    }
}
